home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / tess / tess-1.0 / GeneratorOverlay.m < prev    next >
Encoding:
Text File  |  1992-06-30  |  3.8 KB  |  190 lines

  1. #import "GeneratorOverlay.h"
  2. #import "aGroup-inter.h"
  3. #import "Underlay.h"
  4. #define  BX  bounds.origin.x
  5. #define  BY  bounds.origin.y
  6. #define  BW  bounds.size.width
  7. #define  BH  bounds.size.height
  8. #define RESIZE 0
  9. #define ROTL 1
  10. #define ROTR 2
  11. #define DEFSIZ 200.0
  12.  
  13. @implementation GeneratorOverlay
  14. + new
  15. {
  16.   self = [super new];
  17.   bframe.origin.x = bframe.origin.y = 0.0;
  18.   bframe.size.width = bframe.size.height = GENOFFT;
  19.   rebut = [[Button new]
  20.        initFrame: &bframe icon: "sizer" tag: RESIZE target: self 
  21.        action: @selector(resizeAction:) key: 0 enabled: YES];
  22.   [[rebut cell] sendActionOn: NX_MOUSEDOWNMASK];
  23.   [self addSubview: rebut];
  24.   [self setAutoresizeSubviews: YES];
  25.   group = nil;
  26.   return self;
  27. }
  28.  
  29. - setupGenerator: (id) agroup
  30. {
  31.   float x,y;
  32.   
  33.   x = y = DEFSIZ;
  34.   resizing = NO;
  35.   if (group != nil)
  36.     [group removeFromSuperview];
  37.   group = agroup;
  38.   [self addSubview: group : NX_BELOW relativeTo: rebut]; // install new group as subview
  39.   [group sizeKludge: &x : &y];
  40.   [self sizeTo: x + 2* GENOFFT : y + 2 * GENOFFT];
  41.   [group setGenovly: self];
  42.   [group setupControls];
  43.   [group defaultConfig];
  44.   [group moveTo: GENOFFT : GENOFFT];
  45.   [group sizeTo: x : y];
  46.   [self moveTo: 0.0 : 0.0 ];
  47.   [self placeResizer];
  48.   return self;
  49. }
  50.  
  51. - generatorDidResize
  52. {
  53.   NXSize *si;
  54.  
  55.   [group getGeneratorSize: si];
  56. #ifdef DEBUG
  57.   fprintf(stderr,"Generator size is: %f %f\n",si->width,si->height);
  58. #endif
  59.   [self sizeTo: si->width + 2.0* GENOFFT : si->height + 2.0 * GENOFFT ];
  60.   [self placeResizer];
  61.   return self;
  62. }
  63.  
  64. - erase
  65. {
  66.   scratch = [under getImage];
  67.   if([self lockFocus])
  68.     [scratch composite: NX_COPY fromRect: &frame toPoint: &(bounds.origin)];
  69.   else {
  70.     [scratch composite: NX_COPY fromRect: &frame toPoint: &(bounds.origin)];
  71.     [self unlockFocus];
  72.   }
  73.   return self;
  74. }
  75.  
  76. - drawSelf:(const NXRect *)rects :(int)rectCount
  77. {
  78.   // draw transparent rect filling view
  79.   PSsetrgbcolor(0.0,1.0,1.0);
  80.   PSsetalpha(0.5);
  81.   PScompositerect(BX,BY,BW,BH,NX_SOVER);
  82.   // group object draws seethrough part
  83.   return self;
  84. }
  85.  
  86. - getImage
  87. {
  88.   return [under getImage];
  89. }
  90.  
  91. - setUnderlay: (id) pad
  92. {
  93.   under = pad;
  94.   return self;
  95. }
  96.  
  97. - getGeneratorOffset: (NXPoint *) pt
  98. {
  99.   pt->x = frame.origin.x + GENOFFT;
  100.   pt->y = frame.origin.y + GENOFFT;
  101.   return self;
  102. }
  103.  
  104. - mouseDownAction:(NXPoint *)pt
  105. {
  106.   dx = pt->x;
  107.   dy = pt->y; 
  108.   return self;
  109. }
  110.  
  111. - mouseUpAction:(NXPoint *)pt
  112. {
  113.   resizing=NO;
  114.   return self;
  115. }
  116.  
  117. - mouseDraggedAction:(NXPoint *)pt
  118. //move view under mouse
  119. {
  120.     [self convertPointToSuperview: pt];
  121.     [self erase];
  122.     if(resizing)
  123.       [self resize: pt];
  124.     else {
  125.       pt->x -= dx;
  126.       pt->y -= dy;
  127.       [self moveTo: pt->x : pt->y];
  128.     }
  129.     [self display];
  130.     return self;
  131. }
  132.  
  133. - resize: (NXPoint *) pt
  134. {
  135.   float newh,neww;
  136.   
  137.   [self convertPointFromSuperview: pt];
  138.   neww = pt->x + buttonclickofft.x;
  139.   newh = pt->y + buttonclickofft.y;
  140.   if(neww <= GENOFFT * 3) neww = GENOFFT * 3;
  141.   if(newh <= GENOFFT * 3) newh = GENOFFT * 3;
  142.   if([group isRigidLattice]){
  143.     neww -= 2 * GENOFFT;
  144.     newh -= 2 * GENOFFT;
  145.     [group sizeKludge: &neww : &newh];
  146.     neww += 2 * GENOFFT;
  147.     newh += 2 * GENOFFT;
  148.   }
  149.   [self sizeTo: neww : newh];
  150.   [self placeResizer];
  151.   return self;
  152. }
  153.  
  154. - resizeAction: sender
  155. {
  156.   NXEvent *ev;
  157.   
  158. #ifdef DEBUG
  159.   fprintf(stderr,"ResizeAction\n");
  160. #endif
  161.   ev = [NXApp currentEvent];
  162.   buttonclickofft.x = ev->location.x;
  163.   buttonclickofft.y = ev->location.y;
  164.   [self convertPoint: &buttonclickofft fromView: nil]; // window coords to my coords
  165.   buttonclickofft.x = BW - buttonclickofft.x; // distance from button to edge of self
  166.   buttonclickofft.y = BH - buttonclickofft.y;
  167.   resizing = YES;
  168.   [self becomeFirstResponder];
  169.   [self mouseDown: ev];
  170.   return self;
  171. }
  172.  
  173. - placeResizer 
  174. {
  175.   float x,y;
  176.   NXRect fr;
  177.  
  178.   [rebut getFrame: &fr];
  179.   x = fr.size.width;
  180.   y = fr.size.height;
  181.   [rebut moveTo: BW - x : BH - y];
  182.   return self;
  183. }
  184.  
  185. - rotate: sender 
  186. {
  187.   return self;
  188. }
  189. @end
  190.